package com.yystar.support.base.controller;

import java.util.Date;

import javax.servlet.ServletContext;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.ServletContextAware;

import com.yystar.support.base.typeeditor.DateTypeEditor;
import com.yystar.support.base.typeeditor.DoubleTypeEditor;
import com.yystar.support.base.typeeditor.FloatTypeEditor;
import com.yystar.support.base.typeeditor.IntTypeEditor;
import com.yystar.support.base.typeeditor.LongTypeEditor;

public class BaseController implements ServletContextAware {

	protected static final String DATE_DEFAULT_PARSE_PATTERN = "yyyy-MM-dd";
	protected ServletContext servletContext;

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(int.class, new IntTypeEditor());
		binder.registerCustomEditor(double.class, new DoubleTypeEditor());
		binder.registerCustomEditor(float.class, new FloatTypeEditor());
		binder.registerCustomEditor(long.class, new LongTypeEditor());
		binder.registerCustomEditor(Date.class, new DateTypeEditor(DATE_DEFAULT_PARSE_PATTERN));
	}

	@Override
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
		
	}
}

